
package com.yimixian.app.common;

import com.umeng.analytics.MobclickAgent;
import com.yimixian.app.util.ObservableUtils;

import rx.Subscription;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class YmxActivity extends AppCompatActivity
{

    private List<Subscription> mSubscriptions;
    private Toast mToast;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mSubscriptions = new ArrayList<>();
    }

    protected void registerSubscription(Subscription subscription) {
        mSubscriptions.add(subscription);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        for (Subscription subscription : mSubscriptions) {
            ObservableUtils.unsubscribe(subscription);
        }
        mSubscriptions = null;
    }

    public Toast getToast() {
        return mToast;
    }

    public void setToast(Toast toast) {
        mToast = toast;
    }

    public boolean hasToast() {
        return mToast != null;
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }
}
